#cython:language_level=3
#此文件提供高效的优化计算。Cesium是Rubidium的Cython重制版。

from libc.stdlib cimport malloc, free
cdef class Queue:
    cdef int *q
    cdef int end
    cdef int p
    def __cinit__(self, int length, int Set = 0):
        cdef int i
        self.q = <int*>malloc(length * sizeof(int*))
        for i in range(length):
            self.q[i] = Set
        self.end = length
        self.p = 0 # pointer
    
    def __dealloc__(self):
        if self.q != NULL:
            free(self.q)
    
    cpdef void push(self, int Int):
        self.q[self.p] = Int
        self.p += 1
        if self.p == self.end:
            self.p = 0

    cpdef int get_sum(self):
        cdef int Sum = 0
        cdef int i
        for i in range(self.end):
            Sum += self.q[i]
        return Sum
    
    cpdef float get_averge(self):
        cdef float Sum
        cdef int i
        Sum = 1.0
        for i in range(self.end):
            Sum += self.q[i]
        Sum = Sum / self.end
        return Sum

cpdef str get_version():
    return "Cesium 0.1.1"